package edu.szu.huhanpeng.doodlingFight.controller.dataController.gameStart 
{
	import edu.szu.huhanpeng.doodlingFight.globalConst.GlobalConst;
	import edu.szu.huhanpeng.doodlingFight.interfaces.IChessBoardData;
	import edu.szu.huhanpeng.doodlingFight.interfaces.IChessData;
	import edu.szu.huhanpeng.doodlingFight.interfaces.ISquareData;
	import edu.szu.huhanpeng.doodlingFight.model.ChessBoardProxy;
	import edu.szu.huhanpeng.doodlingFight.model.data.ChessData;
	import org.puremvc.as3.interfaces.ICommand;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.interfaces.INotifier;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	/**
	 * ...
	 * @author Huhanpeng
	 */
	public class InitFriendDc extends SimpleCommand implements ICommand, INotifier 
	{
		
		override public function execute(note:INotification):void 
		{
			var chessBoardProxy:ChessBoardProxy = facade.retrieveProxy(ChessBoardProxy.NAME) as ChessBoardProxy;
			var allSquare:Vector.<ISquareData> = chessBoardProxy.allSquare;
			
			var square:ISquareData;
			var chess:IChessData;
			for (var j:int = 0; j < allSquare.length; j++) 
			{
				square = allSquare[j];
				chess = square.chessData;
				chess.resetFriend();
			}
			
			for (var i:int = 0; i < allSquare.length; i++) 
			{
				
				square = allSquare[i];
				chess = square.chessData;
				
				
				if (square.rightSquare != null) 
				{
					//检查左右
					if (chess.type == square.rightSquare.chessData.type) 
					{
						chess.friend[ChessData.SIX] = square.rightSquare.chessData;
						chess.friend[ChessData.SIX].friend[ChessData.FOUR] = chess;
					}
					
					
					//检查右下与左上
					if (square.RDSquare != null) 
					{
						if (chess.type == square.RDSquare.chessData.type) 
						{
							chess.friend[ChessData.NINE] = square.RDSquare.chessData;
							chess.friend[ChessData.NINE].friend[ChessData.ONE] = chess;
						}
					}
					
					//检查右上与左下
					if (square.RUSquare != null) 
					{
						if (chess.type == square.RUSquare.chessData.type) 
						{
							chess.friend[ChessData.THREE] = square.RUSquare.chessData;
							chess.friend[ChessData.THREE].friend[ChessData.SEVEN] = chess;
						}
					}
				}
				
				//检查上下
				if (square.downSquare != null) 
				{
					if (chess.type == square.downSquare.chessData.type) 
					{
						chess.friend[ChessData.EIGHT] = square.downSquare.chessData;
						chess.friend[ChessData.EIGHT].friend[ChessData.TWO] = chess;
					}
				}
			}
			
			

		}
		
	}

}